//
//  CommentTableView.m
//  CloudWeibo
//
//  Created by CLOUD on 1/3/15.
//  Copyright (c) 2015 Cloud. All rights reserved.
//

#import "CommentTableView.h"
#import "CommentCell.h"

@implementation CommentTableView

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        // Initialization code
    }
    return self;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identify = @"CommentCell";
    CommentCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"CommentCell" owner:self options:nil]lastObject];
    }
    
    CommentModel *commentModel = [self.data objectAtIndex:indexPath.row];
    cell.commentModel = commentModel;
    
    return cell;
}

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CommentModel *commentModel = [self.data objectAtIndex:indexPath.row];
    float height = [CommentCell getCommentHeight:commentModel];
    return height +40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.width, 40)];
    view.backgroundColor = [UIColor whiteColor];
    
    UILabel *commentCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 20)];
    commentCountLabel.backgroundColor = [UIColor clearColor];
    commentCountLabel.font = [UIFont boldSystemFontOfSize:16.0f];
    commentCountLabel.textColor = [UIColor blueColor];
    NSNumber *total = [self.commentDic objectForKey:@"total_number"];
    commentCountLabel.text = [NSString stringWithFormat:@"评论数：%@", total];
    
    UIImageView *separateLine = [[UIImageView alloc] initWithFrame:CGRectMake(0, 39, tableView.width, 1)];
    separateLine.image = [UIImage imageNamed:@"userinfo_header_separator.png"];
    
    [view addSubview:commentCountLabel];
    [view addSubview:separateLine];
    
    [commentCountLabel release];
    [separateLine release];
    return [view autorelease];
}

- (float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
   
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}

@end
